package com.nf.health.app.activity.home.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.nf.health.app.R;
import com.nf.health.app.activity.home.bean.MyBinnerHomeModel;
import com.nf.health.app.widget.InfinitePagerAdapter;

import java.util.List;

/**
 * Created by Jason on 2016/3/16.
 */
public class NewAdsAdapter extends InfinitePagerAdapter {

    private Activity context;
    private List<MyBinnerHomeModel> list;
    private LayoutInflater inflater;


    public NewAdsAdapter(Activity context,  List<MyBinnerHomeModel> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup container) {
        //final ImageView imageView = (ImageView) inflater.inflate(R.layout.item_infinite_viewpager, container, false);
        ViewHolder holder = null;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.activity_bennary, null);
            holder = new ViewHolder();
            holder.imageView = (ImageView) convertView.findViewById(R.id.iv_bennary);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        //ImageLoaderUtils.getinstance(context).getImage(holder.imageView, list.get(position).getImg(), R.drawable.default_square_image);
        //ImageView imageView = null;

        Glide.with(context)
                .load(list.get(position).getHimg())
                .placeholder(R.drawable.iv_home_nation)
                .into(holder.imageView);
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Bundle bundle = new Bundle();
//                WebModel webModel = new WebModel();
//                webModel.setUrl(list.get(position).getHimg());
//                bundle.putSerializable(WebModel.WEBFLAG_TAG, webModel);
//                ActivityUtils.showActivity(context, NewWebViewActivity.class, bundle);
            }
        });

        return convertView;
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }
    public void setTagValues(ImageView imageView,int position,int tag){
        if(imageView.getTag(tag) == null){
            imageView.setTag(tag,list.get(position).getHimg());
            Glide.with(context)
                    .load(list.get(position).getHimg())
                    .placeholder(R.drawable.default_square_image)
                    .into(imageView);
        }else{
            String getTag = (String) imageView.getTag(tag);
            /*if(!getTag.equals(list.get(position).getImg())){
                Glide.with(context)
                        .load(list.get(position).getImg())
                        .placeholder(R.drawable.default_square_image)
                        .into(imageView);
            }*/
        }
    }
    private class ViewHolder{
        ImageView imageView;
    }
}
